/*
 * @Author: 谢小康 2170673706@qq.com
 * @Date: 2024-01-03 21:24:33
 * @LastEditors: 谢小康 2170673706@qq.com
 * @LastEditTime: 2024-02-04 18:51:20
 * @FilePath: \My-bolg\My_Blog\vite.config.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
export default defineConfig({
  plugins: [
    vue(),
    // 自动导入element plus组件
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: "@import '@/style/index.scss';"
      }
    }
  },
  server:{
    port: 8080,
      host: "127.0.0.1",
    https: false,
    open: true,
    // 热更新
    hmr: {
      overlay: false,
    },
    proxy: {
      //匹配规则
      "/api": {
        //要访问的跨域的域名
        target: "http://localhost:8088",
        changeOrigin: true,
      },
      "/wapi": {
        //要访问的跨域的域名
        target: "http://localhost:3000",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/wapi/, ""),
      },
    },
  },
  build:{
    terserOptions: {
      compress: {
        drop_console: true, // 生产环境去掉控制台 console
        drop_debugger: true, // 生产环境去掉控制台 debugger 默认就是true
        dead_code: true, // 删除无法访问的代码 默认就是true
      }
    },
    chunkSizeWarningLimit: 2000, // 调整区块大小警告限制
  }
})
